package com.example.module_inspection

import android.graphics.Color
import android.widget.ImageView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.yuwei.http.entity.InspectionEntityItem
import com.yuwei.http.entity.PatrolEntityItem
import org.xml.sax.helpers.ParserAdapter

class InspectionAdapter:BaseQuickAdapter<InspectionEntityItem,BaseViewHolder>(R.layout.inspection_item) {
    private var list = mutableListOf<PatrolEntityItem>()
    private var positionList = mutableListOf<PatrolEntityItem>()
    fun setList(list:MutableList<PatrolEntityItem>){
        this.list = list
    }
    val patrolAdapter = PatrolAdapter()
    override fun convert(holder: BaseViewHolder, item: InspectionEntityItem) {
    val rv = holder.getView<RecyclerView>(R.id.inspection_item_lx)
    rv.adapter = patrolAdapter
    rv.layoutManager = LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false)
    patrolAdapter.data.addAll(positionList)
    patrolAdapter.notifyDataSetChanged()
    positionList.clear()
    item.patrolPoints.forEach {
        positionList.add(list[it])
    }


    if (item.patrolStatus == "0"){
            val image = holder.getView<ImageView>(R.id.inspection_item_image)
            Glide.with(context).load(R.drawable.sunrise).circleCrop().into(image)
            holder.setText(R.id.inspection_item_name,item.patrolPerson)
            holder.setText(R.id.inspection_item_zw,"保安部成员")
            holder.setText(R.id.inspection_item_time,item.patrolTime.toString())
            holder.setText(R.id.inspection_item_type,"未巡检")
                .setTextColor(R.id.inspection_item_type,Color.parseColor("#999FA8"))
                .setBackgroundResource(R.id.inspection_item_type,R.drawable.inspection_type_bg)

        }
        if (item.patrolStatus == "1"){
            val image = holder.getView<ImageView>(R.id.inspection_item_image)
            Glide.with(context).load(R.drawable.sunrise).circleCrop().into(image)
            holder.setText(R.id.inspection_item_name,item.patrolPerson)
            holder.setText(R.id.inspection_item_zw,"保安部成员")
            holder.setText(R.id.inspection_item_time,item.patrolTime.toString())
            holder.setText(R.id.inspection_item_type,"巡检中")
                .setTextColor(R.id.inspection_item_type,Color.parseColor("#8BC34A"))
                .setBackgroundResource(R.id.inspection_item_type,R.drawable.inspection_type_bg1)

        }
        if (item.patrolStatus == "2"){
            val image = holder.getView<ImageView>(R.id.inspection_item_image)
            Glide.with(context).load(R.drawable.sunrise).circleCrop().into(image)
            holder.setText(R.id.inspection_item_name,item.patrolPerson)
            holder.setText(R.id.inspection_item_zw,"保安部成员")
            holder.setText(R.id.inspection_item_time,item.patrolTime.toString())
            holder.setText(R.id.inspection_item_type,"已完成")
                .setTextColor(R.id.inspection_item_type,Color.parseColor("#999FA8"))
                .setBackgroundResource(R.id.inspection_item_type,R.drawable.inspection_type_bg)
        }
        if (item.patrolStatus == "3"){
            val image = holder.getView<ImageView>(R.id.inspection_item_image)
            Glide.with(context).load(R.drawable.sunrise).circleCrop().into(image)
            holder.setText(R.id.inspection_item_name,item.patrolPerson)
            holder.setText(R.id.inspection_item_zw,"保安部成员")
            holder.setText(R.id.inspection_item_time,item.patrolTime.toString())
            holder.setText(R.id.inspection_item_type,"已作废")
                .setTextColor(R.id.inspection_item_type,Color.parseColor("#999FA8"))
                .setBackgroundResource(R.id.inspection_item_type,R.drawable.inspection_type_bg)

        }


    }
}